<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello React</title>
</head>
<body>

  <div id="root"></div>

  <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.15.4/babel.min.js"></script>
  
  <script type="text/babel">
    const root = ReactDOM.createRoot(document.querySelector("#root"))

    // 1. 将文本定义成变量
    let message = 'hello world'

    // 2.监听按钮的点击
    function btnClick() {
      message = '你好'
      // 4. 重新渲染
      rootRender()
    }

    // 第一次渲染
    rootRender()
    // 3. 封装渲染函数 
    function rootRender() {
      // jsx中绑定数据全用{}
      root.render((
        <div>
          <h2>{message}</h2>
          <button onClick={btnClick}>修改文本</button>
        </div>
      ))
    }
  </script>
</body>
</html>